from sys import argv
# 以命令行的方式输入文件名
script, filename = argv

print(f"We're going to erase {filename}.")
print("If  you don't want that, hit CTRL-C (^C).")
print("If you do want that, hit RETURN.")

input("?")

print("Opening the file...")
# 以写的方式打开文件
target = open(filename,'w')

print("Truncating the file. Goodbye!")
# 清空文件内容
target.truncate()

print("Now I'm going to ask you for three lines.")

# 输入准备写入文件的第一行、第二行、第三行内容
line1 = input("line 1: ")
line2 = input("line 2: ")
line3 = input("line 3: ")

print("I'm going to write these to the file.")

# 写文件，每写完一行，换行之后再输入下一行
# target.write(line1)
# target.write("\n")
# target.write(line2)
# target.write("\n")
# target.write(line3)
# target.write("\n")

target.write(line1 + '\n' + line2 + '\n' + line3 + '\n')

print("And finally,we close it.")
# 关闭文件
target.close()
